package com.example.jedis_pool.test;

import com.example.jedis_pool.jedis_config.Config;
import redis.clients.jedis.Jedis;

import java.util.List;

public class testList {

    //获取连接
    private static Jedis jedis= Config.JedisPool().getResource();

    public static void main(String[] args) {

        testList.setKeyValue();
        testList.getKeyValue();
        //关闭连接
        jedis.close();

    }

    //创建list列表，value值list-value-0到list-value-5
    public static void setKeyValue(){
        //更改到索引为1的数据库
        jedis.select(1);
        //清空数据库
        jedis.flushDB();
        jedis.lpush("list","list-value-0","list-value-1","list-value-2","list-value-3","list-value-4","list-value-5");
        jedis.rpush("list","list-value-6","list-value-7");

    }

    public static void getKeyValue(){

        long l = jedis.llen("list");
        System.out.println(l);
        //从左右两边各弹出一个值
        System.out.println("从左边弹出值："+jedis.lpop("list")+"从右边弹出值："+jedis.rpop("list"));//pop从列表中删除
        List<String> strList=jedis.lrange("list",5,5);//获取值并不从列表中删除
        System.out.println(strList);
        String s= jedis.lindex("list",5);
        System.out.println("获取指定索引位置的值："+s);//不删除
        //从左边删除n个value
        long l1 = jedis.lrem("list",6,"list-value-4");//返回long型的值，表示删除了几个
        System.out.println(l1);

    }

}
